﻿using LuaInterface;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace WWISE
{
    public static class WwiseBehavior
    {
        //是否显示Wwise的报错信息
        public static bool IsShowWwiseErrorLog = true;

        // 播放音乐/音效/语音
        public static void Play(string f_Event,string f_Bnk,GameObject emitterGO,int wwiseFlag, Action action = null)
        {
            if (!string.IsNullOrEmpty(f_Event))
            {
                WwiseManager.Instance.Play(f_Event, f_Bnk, emitterGO, wwiseFlag, action);
            }
        }
		// 改变音量
		public static void SetVolume(float volume, int wwiseFlag)
        {
            WwiseManager.Instance.SetVolume((int)volume, wwiseFlag);
        }

        //设置RTPC值 
        public static AKRESULT SetRTPCValue(string inPszRtpcName, float inValue)
        {
            return AkSoundEngine.SetRTPCValue(inPszRtpcName, inValue);
        }

        //切换
        public static AKRESULT SetSwitch(string inPszSwitchGroup, string inPszSwitchState, UnityEngine.GameObject inGameObjectId)
        {
            if(inGameObjectId)
            {
                WwiseManager.Instance.RegisterGameObj(inGameObjectId);
            }
            else
            {
                inGameObjectId = WwiseManager.Instance.MusicEmitter;
            }
            return AkSoundEngine.SetSwitch(inPszSwitchGroup, inPszSwitchState, inGameObjectId);
        }

        //发送事件
        public static void PostTrigger(string triggerName, UnityEngine.GameObject inGameObjectId)
        {
            AkSoundEngine.PostTrigger(triggerName, inGameObjectId);
        }

        //切换语言包
        public static void SetCurrentLanguage(string newLanguageName)
        {
            if(!string.IsNullOrEmpty(newLanguageName))
            {
                string _currentLanguage = AkSoundEngine.GetCurrentLanguage();
                if(_currentLanguage != newLanguageName)
                {
                    AkSoundEngine.SetCurrentLanguage(newLanguageName);
                }
            }
        }

        

        //        //注册游戏对象
        //        public static AKRESULT RegisterGameObj(UnityEngine.GameObject gameObject)
        //        {
        //#if USE_WWISE
        //            return AkSoundEngine.RegisterGameObj(gameObject);
        //#endif
        //            return AKRESULT.AK_Fail;
        //        }
        //    //注销游戏对象
        //        public static AKRESULT UnregisterGameObj(UnityEngine.GameObject gameObject)
        //        {
        //#if USE_WWISE
        //            // 设置账号 ID
        //          return AkSoundEngine.UnregisterGameObj(gameObject);
        //#endif
        //            return AKRESULT.AK_Fail;
        //        }
        //        //全部注销
        //        public static void UnregisterAllGameObj()
        //        {
        //#if USE_WWISE
        //            AkSoundEngine.UnregisterAllGameObj();
        //#endif
        //        }

        //        //发送事件
        //        public static void PostEvent(string eventName, UnityEngine.GameObject inGameObjectId)
        //        {
        //#if USE_WWISE
        //           AkSoundEngine.PostEvent(eventName, inGameObjectId);
        //#endif
        //        }

        //设置状态
        public static void SetState(string inPszStateGroup, string inPszState)
        {
            AkSoundEngine.SetState(inPszStateGroup, inPszState);
        }

        //异步加载SoundBank
        public static void LoadBankAsync(string bankName,LuaFunction luaCallback)
        {
            WwiseManager.Instance.LoadBankAsync(bankName,luaCallback);
        }

        public static void UnloadBank(string bankName)
        {
            WwiseManager.Instance.UnLoadSoundBank(bankName);
        }
    }
}


